package net.sudot.commons.utils;

import net.sudot.commons.json.JsonUtils;

import java.io.Serializable;

/**
 * 响应信息封装
 *
 * @time 2015年12月15日
 */
public class ResponseMessage implements Serializable {
    private static final long serialVersionUID = -4714259069678234112L;
    /** 业务状态:true:成功;false:失败 */
    private boolean success = false;
    /** 业务代码 */
    private int code = 0;
    /** 响应内容 */
    private String message;
    /** 响应扩展数据 */
    private Object data;

    public ResponseMessage() {
    }

    public ResponseMessage(boolean success) {
        this.success = success;
    }

    public ResponseMessage(boolean success, int code) {
        this.success = success;
        this.code = code;
    }

    public ResponseMessage(boolean success, int code, Object data) {
        this.success = success;
        this.code = code;
        this.data = data;
    }

    public ResponseMessage(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public ResponseMessage(boolean success, String message, Object data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public ResponseMessage setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public int getCode() {
        return code;
    }

    public ResponseMessage setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResponseMessage setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ResponseMessage setData(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JsonUtils.toJson(this);
    }
}
